package cn.tedu.tmall.front.mall.dao.persist.repository.impl;

import cn.tedu.tmall.front.mall.dao.persist.mapper.ReceiverAddressMapper;
import cn.tedu.tmall.front.mall.dao.persist.repository.IReceiverAddressRepository;
import cn.tedu.tmall.front.mall.pojo.entity.ReceiverAddress;
import cn.tedu.tmall.front.mall.pojo.vo.ReceiverAddressListItemVO;
import cn.tedu.tmall.front.mall.pojo.vo.ReceiverAddressStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Slf4j
public class ReceiverAddressRepository implements IReceiverAddressRepository {
    @Autowired
    private ReceiverAddressMapper receiverAddressMapper;
    @Override
    public int insert(ReceiverAddress receiverAddress) {
        log.debug("开始执行插入收货地址");
        return receiverAddressMapper.insert(receiverAddress);
    }

    @Override
    public int updateNotDefaultByUser(Long userId) {
        log.debug("开始执行将用户的所有默认收货地址设置为默认的");
        ReceiverAddress receiverAddress=new ReceiverAddress();
        receiverAddress.setIsDefault(0);
        QueryWrapper<ReceiverAddress> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_id",userId);
        return receiverAddressMapper.update(receiverAddress,queryWrapper);
    }

    @Override
    public ReceiverAddressStandardVO getStandardById(Long id) {
        log.debug("根据id查询收货地址");
        return receiverAddressMapper.getStandardById(id);
    }

    @Override
    public List<ReceiverAddressListItemVO> listByUser(Long userId) {
        log.debug("根据用户查询收货地址");
        return receiverAddressMapper.listByUser(userId);
    }
}
